# Create a library for the math functions
add_library(sve_bonus
    task1/saxpy.cpp
    task2/gemv.cpp
    task3/pack.cpp
)


set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

include(ExternalProject)
ExternalProject_Add(
    ggml
    GIT_REPOSITORY git@github.com:ggml-org/ggml.git
    GIT_TAG 6757e32
    GIT_SUBMODULES ""
    GIT_SUBMODULES_RECURSE FALSE
    GIT_PROGRESS TRUE

    UPDATE_COMMAND ""
    CONFIGURE_COMMAND ""
    PATCH_COMMAND ""
    INSTALL_COMMAND ""
    BUILD_COMMAND ""
)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/task4/include
    ${CMAKE_BINARY_DIR}/src/ggml-prefix/src/ggml/include
    ${CMAKE_BINARY_DIR}/src/ggml-prefix/src/ggml/src
)

add_library(gemv SHARED
    task4/gemv.cpp
)

add_library(gemv-sve SHARED
    task4/gemv-sve.cpp
)

target_compile_options(
    gemv PRIVATE
    -Wall
    -Wextra
    -fPIC
    -O2
    -march=native
)

target_compile_options(
    gemv-sve PRIVATE
    -Wall
    -Wextra
    -fPIC
    -O2
    -march=native
)

target_include_directories(sve_bonus PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/task1
    ${CMAKE_CURRENT_SOURCE_DIR}/task2
    ${CMAKE_CURRENT_SOURCE_DIR}/task3
)

# Enable ARM SVE support
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
    target_compile_options(sve_bonus PRIVATE -march=armv8-a+sve)
endif()


# Disable vectorization
target_compile_options(sve_bonus PRIVATE -O3 -fno-tree-vectorize)
